package com.employee.config;

import com.employee.mapper.ReqMapper;
import com.employee.pojo.vo.ReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * 定时任务
 */
@Configuration
@EnableScheduling
public class ReqConfig {

    @Autowired
    private ReqMapper reqMapper;

    // @Scheduled(fixedDelay = 5000) // 每5秒执行一次
    @Scheduled(cron = "0 0 2 * * ?") // 每天晚上2点执行
    // @Scheduled(cron = "0 40 16 * * ?") // 每天晚上16点33执行
    public void fixedDelayTask() {
        List<ReqVO> reqVOList1 = reqMapper.selectNotClock();
        List<ReqVO> reqVOList2 = reqMapper.selectNotClockOne();
        reqVOList1.addAll(reqVOList2);
        reqVOList1.forEach(System.out::println);
        reqMapper.insertAll(reqVOList1);
        System.out.println("定时任务执行了");
    }
}
